package top.purity.framework.orm.jpa;

import lombok.extern.slf4j.Slf4j;
import org.hibernate.engine.jdbc.connections.spi.AbstractDataSourceBasedMultiTenantConnectionProviderImpl;
import org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @version 1.0
 * @Author Lmh
 * @Description
 * @CreateTime 2023-10-29 17:12
 */

@Slf4j
@Component
public class TenantProvider extends AbstractDataSourceBasedMultiTenantConnectionProviderImpl<String> {

    /**
     * 没有租户id的清空下访问的数据库
     * @return
     */
    @Override
    protected DataSource selectAnyDataSource() {
        log.info("selectAnyDataSource");
        return null;
    }

    /**
     * 有租户id的情况下访问数据库
     * @param tenantIdentifier
     * @return
     */
    @Override
    protected DataSource selectDataSource(String tenantIdentifier) {
        log.info("selectDataSource: {}", tenantIdentifier);
        return null;
    }
}
